<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="listQuery.type" placeholder="请选择" @change="getList">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>


      <el-input
        class="filter-item"
        placeholder="用户名/手机号/合同名"
        v-model="listQuery.keyword"
        style="width: 20%;margin-left:5px;"
      >
      </el-input>

      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getList"
                 style="margin-left: 5px"
      >
        搜索
      </el-button>
    </div>
    <el-card>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="ID" min-width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="100" align="center" label="用户名/手机">
        <template slot-scope="scope">
          <el-link type="primary" v-if="scope.row.mobile">{{ scope.row.mobile }}</el-link>
          <el-link type="success" v-else>{{scope.row.nickname}}</el-link>
          <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
        </template>
      </el-table-column>
      <el-table-column min-width="150" align="center" label="合同标题" v-if="listQuery.type ==1">
        <template slot-scope="scope">
          <span>{{ scope.row.title }}</span>
          <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
        </template>
      </el-table-column>
      <el-table-column min-width="150" align="center" label="专题标题" v-if="listQuery.type ==2">
        <template slot-scope="scope">
          <span>{{ scope.row.s_title }}</span>
          <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
        </template>
      </el-table-column>

      <el-table-column label="封面图" min-width="80" align="center">
        <template slot-scope="{row}">
          <el-tooltip content="点击放大" placement="right" effect="light">
            <el-image
              v-if="listQuery.type ==1"
              style="width: 50px; height: 50px"
              :src="row.title_pic"
              lazy
              fit="contain"
              @click="showBanner(row.title_pic)"
            ></el-image>
            <el-image
              v-else
              style="width: 50px; height: 50px"
              :src="row.image"
              lazy
              fit="contain"
              @click="showBanner(row.image)"
            ></el-image>
          </el-tooltip>
        </template>
      </el-table-column>


      <el-table-column min-width="120" align="center" label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.created_at }}</span>
        </template>
      </el-table-column>
    </el-table>
    </el-card>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                @pagination="getList"
    />
    <el-dialog :visible.sync="dialogBannerVisible" width="80%">
      <center>
        <el-image fit="contain" :src="showBannerUrl" width="100%"></el-image>
      </center>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from '@/api/down_history'
// import { getMenus } from '@/api/menu'
import Pagination from '@/components/Pagination'
import store from '@/store'
import router from '@/router' // Secondary package based on el-pagination
import ImageCropper from '@/components/ImageCropper'
import PanThumb from '@/components/PanThumb'
import { formatMoney } from '@/api/util'
export default {
  name: 'Member/Down_history',
  components: { Pagination, ImageCropper, PanThumb },
  filters: {
    moenyFormat(value){
      if (!value) return ''
      return formatMoney(value)
    }
  },
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      dialogBannerVisible: false,
      showBannerUrl: '',
      todayMoney:'',
      typeList:[],
      imagecropperShow: false,
      imagecropperKey: 0,
      menus: [],
      roles: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        keyword: '',
        type:1,

      },
      options: [{
        value: 1,
        label: '合同'
      }, {
        value: 2,
        label: '专题'
      }],
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      filterText: '',
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      timeMoney:''
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.getList()
  },
  methods: {
    showBanner(url) {
      this.showBannerUrl = url
      this.dialogBannerVisible = true
    },
    getList() {
      this.listLoading = true
      getList(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.total
        this.listLoading = false
      })
    },
    resetForm() {
      this.dialogFormVisible = false
    },
    resetTemp() {

    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}

.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
<style scoped>
.avatar {
  width: 200px;
  height: 200px;
  border-radius: 50%;
}
</style>
